<template>
  <a-table
    :columns="columns"
    :row-key="record => record.login.uuid"
    :data-source="data"
    :pagination="pagination"
    :loading="loading"
    @change="handleTableChange"
  >
<!--    <template slot="name" slot-scope="name"> {{ name.first }} {{ name.last }} </template>-->
  </a-table>
</template>
<script>
  const columns = [
    {
      title: '采购订单号',
      align: 'center',
      dataIndex: 'purchaseorderNo'
    },
    {
      title: '订单类型',
      align: 'center',
      dataIndex: 'purchaseorderType'
    },
    {
      title: '采购订单号',
      align: 'center',
      dataIndex: 'erppurchaseOrderno'
    }
  ]

  export default {
    data() {
      return {
        data: [],
        pagination: {},
        loading: false,
        columns
      }
    },
    mounted() {
      this.fetch()
    },
    methods: {
      handleTableChange(pagination, filters, sorter) {
        console.log(pagination)
        const pager = { ...this.pagination }
        pager.current = pagination.current
        this.pagination = pager
        this.fetch({
          results: pagination.pageSize,
          page: pagination.current,
          sortField: sorter.field,
          sortOrder: sorter.order
        })
      },
      fetch(params = {}) {
        console.log('params:', params)
        this.loading = true

        this.http.get(this, {
          url: this.api.project.projectStatus,
          data: {
          },
          success: function (me, data) {
            const pagination = { ...this.pagination }
            // Read total count from server
            // pagination.total = data.totalCount;
            pagination.total = 200
            this.loading = false
            this.data = data.results
            this.pagination = pagination
          }
        })

        reqwest({
          url: 'https://randomuser.me/api',
          method: 'get',
          data: {
            results: 10,
            ...params,
          },
          type: 'json',
        }).then(data => {
          const pagination = { ...this.pagination };
          // Read total count from server
          // pagination.total = data.totalCount;
          pagination.total = 200;
          this.loading = false;
          this.data = data.results;
          this.pagination = pagination;
        });
      },
    },
  };
</script>
